#include<iostream>
#include<string>
#include <fstream>
using namespace std;
int main()
{
    FILE *fp;
    char ch;
    int character=0,word=0,sentence=0,number=0,note=0;    
    char x[10];
    for(;;)
 {
     cout<<"请以wc.exe [参数] [文件名]的形式输入"<<endl;
     cout<<"参数为-c、-w、-s"<<endl;

     string a;
     cin>>a;
     if(a!="wc.exe")
	  {
         cout<<"请先输入wc.exe"<<endl;
	  }
     cin>>x;
     if(x[1]=='c')
	 {
      string b;
      cin>>b;
            if((fp=fopen((b).c_str(),"r"))==NULL)    // fopen打开所指向的文件"r"读取文件，文件必须存在。 
			{
            cout<<"文件路径错误"<<endl;
			}
      //   ch=fgetc(fp);
      while((ch = fgetc(fp)) != EOF)
	  {
           character++;
      //  ch=fgetc(fp);
	  }
      fclose(fp);
      cout<<"字符数为："<<character<<endl;
	}
     else if(x[1]=='w')
	 {
            string b;
      cin>>b;
            if((fp=fopen((b).c_str(),"r"))==NULL)    //到达文件末尾或者发生读错误，则返回EOF
			{
            cout<<"文件路径错误"<<endl;
			}
      ch=fgetc(fp);
         for(;ch!=EOF;)
		 {
          if(ch==' '||ch==','||ch=='.'||ch=='!'||ch==';'||ch==':'||ch=='?'||ch=='、'||ch=='"'||ch=='\''||ch=='\n'||ch=='\0')
		  {
           word++;
		  }
          ch=fgetc(fp);
		 }
         fclose(fp);
      cout<<"单词数为："<<word<<endl;
	 }
     else if(x[1]=='s')
	 {
            string b;
      cin>>b;
            if((fp=fopen((b).c_str(),"r"))==NULL)    
			{
             cout<<"文件路径错误"<<endl;
			}
            ch=fgetc(fp);
            for(;ch!=EOF;)
			{
             if(ch=='.'||ch=='!'||ch=='?')
			 {
               sentence++;
			 }
             ch=fgetc(fp);
			}
            fclose(fp);
            cout<<"句子数为："<<sentence<<endl;
	 }
     else
	 {
      cout<<"命令错误，请输入正确的命令!"<<endl;
	 }
  }
 return 0;
}